<?php

// TODO: Still missing some work on formats ... but this will do for now

class Pldkp_View_Helper_DateTimePicker extends ZendX_JQuery_View_Helper_UiWidget
{
    const DATE_FORMAT = 'yyyy-MM-dd HH:mm';
    
    public function dateTimePicker($id, $value = null, array $params = array(), array $attribs = array())
    {
        // Encode parameters as json
        if(count($params) > 0) {
            $params = ZendX_JQuery::encodeJson($params);
        } else {
            $params = "{}";
        }
        
        // Setup the value 
        if ($value == null) {
            $date = new Zend_Date(time());
            $value = $date->toString(self::DATE_FORMAT);
        }
        
        // Ensure that the proper javascript and css is loaded
        $baseUrl = $this->view->baseUrl();
        $this->jquery->addJavascriptFile($baseUrl . 'js/jquery/datetime/timepicker.js');
        $this->jquery->addStylesheet($baseUrl . 'js/jquery/datetime/style.css');
        
        $js = sprintf('%s("#%s").datetime(%s);',
            ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(),
            $attribs['id'],
            $params
        );
        
        $this->jquery->addOnLoad($js);
        
        return $this->view->formText($id, $value, $attribs);
    }
}